import $http from '../../http/http.js'
import apiSetting from '../../http/apiSetting.js'
let dayjs = require('dayjs');
let app = getApp();

Page({
  data: {
    selectFacScope: '',
    name: '',
    list: [],
  },
  onLoad() {
    // this.factoryCalendarPlanQuery();
  },
  onShow() {
    this.getList()
  },

  // 新增
  add() {
    dd.navigateTo({
      url: '/pages/planHaltManageAddEdit/planHaltManageAddEdit?type=add'
    })
  },

  // 编辑
  edit(e) {
    let id = e.target.dataset.item.id
    dd.navigateTo({
      url: '/pages/planHaltManageAddEdit/planHaltManageAddEdit?type=edit&id=' + id
    })
  },

  // 选择范围
  selectRange() {
    dd.navigateTo({
      url: '/pages/selectRange/selectRange?type=back'
    })
  },

  // 分⻚查询⼯⼚⽇历计划停产管理列表信息
  factoryCalendarPlanQuery() {
    let that = this;
    $http(apiSetting.factoryCalendarPlanQuery, {
      ftyModelId: '',
      ftyModelValue: '1', // ⼯⼚模型层级值，⼯⼚1，⻋间2， 产线3，加⼯中⼼4，设备5
      pageNo: 1,
      pageSize: 200,
      platForm: app.globalData.systemInfo
    }).then((data) => {
      console.log(data)
    })
  },

  getList() {
    let that = this
    dd.getStorage({
      key: 'selectFacScope',
      success: function (res) {
        console.log(res.data[0])
        that.setData({
          name: res.data[0].title,
          list: []
        })
        that.data.selectFacScope = res.data[0]
        $http(apiSetting.factoryCalendarPlanQuery, {
          ftyModelId: that.data.selectFacScope.key,
          ftyModelValue: that.data.selectFacScope.level + 1,
          pageNo: 1,
          pageSize: 200
        }).then((data) => {
          if (data.code == 0) {
            that.setData({
              list: data.result.data
            })
          }
        })
      },
    });
  }

});
